﻿<!DOCTYPE html>
<html>
<head>
<%
    include("/static/include/title.html"){}
    include("/static/include/css.html"){}
    include("/static/include/js.html"){}
%>
</head>
<body>
<div class="layui-fluid">
	<form id="fView" class="layui-form" method="post" action="##" onsubmit="return false">
		<input type="hidden" id="dialogId" name="dialogId" value="${parameter.dialogId}"/>
		<input type="hidden" name="dbtableId" value="${dbtable.id}"/>
		<div class="layui-card">
			<!-- 如需要header信息，放开下面的comment -->
			<div class="layui-card-header">参数设定</div>
			<div class="layui-card-body" style="padding: 15px;">
				<!-- 如一行显示多列数据，参照下面的示例 -->
				<!--
				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">属性1：</label>
						<div class="layui-input-inline">
							<input type="text" autocomplete="off" class="layui-input" maxlength="25" title="属性1对应控件">
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label">属性2：</label>
						<div class="layui-input-inline">
							<input type="text" autocomplete="off" class="layui-input" maxlength="25" title="属性1对应控件">
						</div>
					</div>
				</div>
				-->
				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">包前缀：</label>
						<div class="layui-input-inline layui-form-mid">${@team.bangbang.common.utility.LogicUtility.getHTMLString(dbtable.packagePrefix)}</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label">创建时间：</label>
						<div class="layui-input-inline layui-form-mid">${dbtable.createTime, "yyyy-MM-dd HH:ss"}</div>
					</div>
				</div>
			</div>
		</div>
		
		<div class="layui-card">
			<div class="layui-card-header">数据库表信息</div>
			<div class="layui-card-body" style="padding: 15px;">
			
				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">表名称：</label>
						<div class="layui-input-inline layui-form-mid">${@team.bangbang.common.utility.LogicUtility.getHTMLString(dbtable.tableName)}</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label">表说明：</label>
						<div class="layui-input-inline layui-form-mid">${@team.bangbang.common.utility.LogicUtility.getHTMLString(dbtable.tableDescription)}</div>
					</div>
				</div>
				
				<table class="layui-table" id="dynamicTable">
					<thead>
					<tr>
						<th width="30" align="center">序号</th>
						<th width="120" align="center">字段</th>
						<th width="100" align="center">类型</th>
						<th width="80" align="center">长度</th>
						<th width="30" align="center">PK</th>
						<th width="40" align="center">NotNull</th>
						<th align="center">字段说明</th>
					</tr>
					</thead>
					<tbody>
					<% if(has(fieldList) && fieldList != null){ for(i in fieldList) {%>
					<tr id="line${iLP.index}">
						<td align="center">${iLP.index}</td>
						<td>${@team.bangbang.common.utility.LogicUtility.getHTMLString(i.fieldName)}</td>
						<td>${i.fieldType}</td>
						<td>${@team.bangbang.common.utility.LogicUtility.getHTMLString(i.fieldLength)}</td>
						<td align="center"><%if(i.isPk) {%><i class="layui-icon layui-icon-ok"></i><%}%></td>
						<td align="center"><%if(i.isNotNull) {%><i class="layui-icon layui-icon-ok"></i><%}%></td>
						<td>${@team.bangbang.common.utility.LogicUtility.getHTMLString(i.fieldDescription)}</td>
					</tr>
					<%}}%>
					</tbody>
				</table>
			</div>
		</div>
			
		<div class="layui-form-item layui-layout-admin">
			<div class="layui-input-inline">
				<div class="layui-footer" style="left: 0;">
					<div class="layui-inline">
						<label class="layui-form-label" style="width:110px;"><span style="color:#FF5722;">基本工作量</span>：</label>
						<div class="layui-input-inline layui-form-mid" style="width:70px;">${dbtable.workload} 人.天</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label" style="width:90px;"><span style="color:#FF5722;">Code模板</span>：</label>
						<div class="layui-input-inline" style="text-align:left;width:300px;">
							<select name="codeTemplate">
								<option value="">--请选择--</option>
								<% if(has(templates) && templates != null){ for(i in templates) {%>
								<option value="${i}">${i}</option>
								<%}}%>
					        </select>
						</div>
					</div>
					<div class="layui-inline">
						<button class="layui-btn" onclick="generateCode();">生成代码</button>
					</div>					
				</div>
			</div>
		</div>
	</form>
</div>
<iframe id="downloadFrame" name="downloadFrame" frameborder="0" width="0" height="0" marginwidth="0"></iframe>
</body>
<script>
	layui.use(['form'], function(){
        var form  = layui.form;
        // 渲染表单radio、select、checkbox
        form.render();
    });
	
	function validate(theForm) {
		// Code模板
		if(theForm["codeTemplate"].value == "") {
			$.message("请选择 Code 摸板！");
			return false;
		}
		
		return true;
	}
	
	function generateCode() {
		var theForm = document.forms[0];
		if(!validate(theForm)) {
			return;
		}
		
	    $.ajax({
	        url: "codeGenerate.do"
	        ,type: "post"
	        ,data: $("#fView").serializeJSON()
	        ,dataType:'json'
	        ,traditional: true
	        ,success:function(result) {
	            if(result == null) {
	            	return;
	            }
	            
	            $.alert(result.message, function() {
	            	document.getElementById("downloadFrame").src = "../common/download?file=" + result.data + "&name=${@team.bangbang.common.utility.LogicUtility.getHTMLString(dbtable.tableName)}.zip";
	            });
	        }
	    });
	}
</script>
</html>
